//
//  ApplyConfirmController.swift
//  xiaoqiao
//
//  Created by 冷子豪 on 2017/8/5.
//  Copyright © 2017年 冷子豪. All rights reserved.
//

import UIKit

class ApplyConfirmController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    @IBAction func applyButton(_ sender: UIButton) {
        /// 确认申请，将全部信息传入后台
        
        
        // MARK: - 1.用户账户信息
        submitUser()
        
        // MARK: - 2.用户详细信息
        submitUserInfo()
        
        // MARK: - 3.用户房产信息
        submitHouses()
//
//        // MARK: - 4.贷款信息
//        submitLoan()
        
        performSegue(withIdentifier: "2certify", sender: nil)
    }
    
    /// 1.用户账户信息
    func submitUser(){
        let jsonStr = jsonKits.toJson(user: user)
        print("[User json]:")
        print(jsonStr)
        
        //json 格式的用户数据
        let jsonStr2 = "jsonUser=\(jsonStr)"
        let data:Data = jsonStr2.data(using: .utf8, allowLossyConversion: true)!
        
        let returnNum = userViewModel.updateUser(data: data)
        
        print("[returnNum]")
        print(returnNum)
    }
    
    /// 2.用户详细信息
    func submitUserInfo(){
        let jsonStr = jsonKits.toJson(user: theUser)
        print("[UserInfo json]:")
        print(jsonStr)
        
        //json 格式的用户详细信息
        let jsonStr2 = "jsonUserInfo=\(jsonStr)"
        let data:Data = jsonStr2.data(using: .utf8, allowLossyConversion: true)!
        
        let returnNum = userInfoViewModel.updateUserInfo(data: data)
        
        print("[returnNum]")
        print(returnNum)
    }
    
    /// 3.用户房产信息
    func submitHouses(){
        let jsonStr = jsonKits.toJson(array: arrayHouse)
        print("[Houses json]:")
        print(jsonStr)
        
        //json 格式的房产信息
        let jsonStr2 = "jsonHouse=\(jsonStr)"
        let data:Data = jsonStr2.data(using: .utf8, allowLossyConversion: true)!
        
        let returnNum = houseViewModel.updateHouseList(data: data)
        
        print("[returnNum]")
        print(returnNum)
    }
    
    /// <#Description#>
    func submitLoan(){
        _ = true
        print("[Loan json]:")
//        print(jsonStr)
        
//        //json 格式的贷款信息
//        let jsonStr2 = "jsonHouse=\(jsonStr)"
//        let data:Data = jsonStr2.data(using: .utf8, allowLossyConversion: true)!
//        
//        let returnNum = (data: data)
//        
//        print("[returnNum]")
//        print(returnNum)
    }
}
